import 'package:flutter/material.dart';
import 'package:flutter_color_plugin/flutter_color_plugin.dart';
import 'package:yw_bapp/utils/precision_limit_formatter.dart';
import 'package:yw_bapp/widgets/show_toast.dart';
// 键盘类型
const type = [
  TextInputType.number,
  TextInputType.visiblePassword,
  TextInputType.text,
  TextInputType.datetime,
  TextInputType.emailAddress,
  TextInputType.multiline,
  TextInputType.phone,
  TextInputType.url,
];
class FiledTagWidget extends StatefulWidget {
  final String tagName; //左侧tag名字
  final String fieldText; //输入的默认值
  final TextStyle textStyle; //左侧tag的自定义样式
  final String hintText; //placeholder
  final ValueChanged<String> changeCallback; //值改变的回调方法
  final bool isEnabled;
  final int typeNum; //键盘类型

  const FiledTagWidget(
      {Key key,
      this.tagName,
      this.fieldText,
      this.textStyle,
      this.hintText,
      @required this.changeCallback,
      this.isEnabled, this.typeNum})
      : super(key: key);
  @override
  _FiledTagWidgetState createState() => _FiledTagWidgetState();
}

class _FiledTagWidgetState extends State<FiledTagWidget> {
  TextEditingController _bankController = TextEditingController();
  @override
  void initState() {
    // TODO: implement initState
    if (widget.fieldText != '') {
      _bankController.text = widget.fieldText;
    }
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Expanded(
      flex: 1,
      child: Container(
        height: 50,
        color: Colors.white,
        padding: EdgeInsets.only(right: 15, left: 15),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            DefaultTextStyle(
              child: Text(
                '${widget.tagName}',
                style: widget.textStyle,
              ),
              style:
                  TextStyle(color: ColorUtil.color("#FF333333"), fontSize: 15),
            ),
            // 输入框
            Container(
              width: 210,
              alignment: Alignment.bottomCenter,
              child: TextField(
                controller: _bankController,
                keyboardType: type[widget.typeNum??0],
                autofocus: false,
                enabled: widget.isEnabled,
                decoration: InputDecoration(
                    border: widget.isEnabled
                        ? UnderlineInputBorder(
                            borderSide: BorderSide(color: Colors.grey))
                        : InputBorder.none,
                    hintText: "${widget.hintText}",
                    helperStyle: TextStyle(
                      color: Colors.transparent,
                    ),
                    focusedBorder: UnderlineInputBorder(
                        borderSide: BorderSide(color: Colors.grey)),
                    hintStyle: TextStyle(
                        color: ColorUtil.color("#FF999999"),
                        fontWeight: FontWeight.normal,
                        fontSize: 13)),
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
                textAlign: TextAlign.right,
                onChanged: (String value) {
                  print('组件内部$value');
                  widget.changeCallback(value);
                },
              ),
            )
          ],
        ),
      ),
    );
  }
}
